﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEECommonTools;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class PloterBufferTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";
        static double tbH = 0;
        #region I梁
        /// <summary>
        /// 挡板高度绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="scale"></param>
        /// <param name="dwgPath"></param>
        /// <param name="dtRes"></param>
        public static void DrawBlockDepthTable(Database db, double scale, string dwgPath, ref System.Data.DataTable dtRes, string plinthCoorPath,string blockParaPath, string pierList,string iAPara, string iBPara, string tAPara, string tBPara,ref string pierdiv,string tkPath="")
        {
            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d ext1 = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
            Point2d M1 = CT;
            ext = new Extents2d(M1, M1);


            System.Data.DataTable dt = CVSTools.OpenCSV(plinthCoorPath);

            System.Data.DataTable dtP = new System.Data.DataTable();
            DataView dv0 = dt.DefaultView;
            dt = dv0.ToTable(true, new string[] { "Pier", "Side", "PlinthNo", "East", "North", "Height", "H0", "ZP_ABS" });
            Dictionary<int, List<string>> dic = new Dictionary<int, List<string>>();
            string[] plist = pierList.Split('|');
            for (int i = 0; i < plist.Length; i++)
            {
                List<string> pl = plist[i].Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(',').ToList();
                dic.Add(i + 1, pl);
                pierdiv = pl[0] + "-" + pl[pl.Count - 1];
            }
           
           //List<string> p3 = new List<string>() { "RP-17", "RP-18", "RP-19", "RP-20", "RP-21" };
           //dic.Add(1, p3);
            List <string> pList = new List<string>();
            Dictionary<int, List<string>> dicI = new Dictionary<int, List<string>>();
            int pageno = dic.Count;

            //pageno = iAPara.Split(',').Length;
            //if (pageno < iBPara.Split(',').Length)
            //    pageno = iBPara.Split(',').Length;
            for (int i = 0; i < pageno; i++)
            {

                List<string> pierL = dic[i + 1];
                System.Data.DataTable dtA = new System.Data.DataTable();
                System.Data.DataTable dtB = new System.Data.DataTable();
                dtA = dt.Clone();
                dtB = dt.Clone();
                if (pierL.Count > 0)
                {
                    foreach (string pierName in pierL)
                    {
                        DataRow[] drs = dt.Select("Pier='" + pierName + "'");

                       DataRow[] drsA = dt.Select("Pier='" + pierName + "' and Side='A' and (PlinthNo like '%-1' or PlinthNo like '%月1日'  or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");

                        if (drsA.Length > 0)
                        {
                            foreach (DataRow item in drs)
                            {
                                if(drsA.Contains(item))
                                  dtA.Rows.Add(item.ItemArray);
                            }
                        }
                        DataRow[] drsB = dt.Select("Pier='" + pierName + "' and Side='B' and (PlinthNo like '%-1' or PlinthNo like '%月1日'  or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");

                        if (drsB.Length > 0)
                        {
                            foreach (DataRow item in drs)
                            {
                                if (drsB.Contains(item))
                                    dtB.Rows.Add(item.ItemArray);
                            }
                        }
                    }
                }

                Table lasTb = new Table();
                ext = new Extents2d(M1.Convert2D(0, -297 * i), M1.Convert2D(0, -297 * i));
                lasTb = DrawingPlinthIBlockDepthTable(db, ref ext, M1.Convert3D(0, -297 * i),
                    Extensions.curFont, scale, dtA, dtB, dwgPath, pierL, iAPara, iBPara,ref dtRes);

                //ext = new Extents2d(M1.Convert2D(0, -297 * i), M1.Convert2D(0, -297 * i));
                //lasTb = DrawingPlinthTBlockDepthTable(db, ref ext, M1.Convert3D(0, -297 * i),
                //    Extensions.curFont, scale, dtA, dtB, dwgPath, pierL,ref dtRes, tAPara, tBPara);
                //DrawBufferRebars();
                Common.CreateLayoutNew(db, "挡板厚度", ext, scale, 1, i, 0,false, tkPath);
            }
        }

        /// <summary>
        /// I梁挡板高度表格绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="dtA"></param>
        /// <param name="dtB"></param>
        /// <param name="_dwgPath"></param>
        /// <param name="pierL"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static Table DrawingPlinthIBlockDepthTable(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable dtA, System.Data.DataTable dtB, string _dwgPath, List<string> pierL, string IAPara, string IBPara , ref System.Data.DataTable dtRes)
        {
            //List<string> pierList = new List<string>();
            List<string> aParas = IAPara.Split('|').ToList();
            List<string> bParas = IBPara.Split('|').ToList();
            Tuple<string,int, string, int, string, int, string> tuple;
            List<Tuple<string, int, string,int, string,int, string>> data=new List<Tuple<string, int, string, int, string, int, string>>();
            int rowCount = 0;
            System.Data.DataRow drP = dtRes.NewRow();
            for (int i = 0; i < pierL.Count; i++)
            {
                int count = 0;
                int countA = 0;
                int countB= 0;
                string aItem = "";
                string bItem = "";
                string type = "";
                if (IAPara.Contains(pierL[i]))
                {
                    //pierList.Add(pierL[i]);
                    string para = aParas.Find(item => item.Contains(pierL[i]));
                    string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                    countA = paras[1].Split(',').Length;
                    aItem = paras[1];
                    type = paras[2];
                }
                if (IBPara.Contains(pierL[i]))
                {
                    //if (!pierList.Contains(pierL[i]))
                    //    pierList.Add(pierL[i]);
                    string para = bParas.Find(item => item.Contains(pierL[i]));
                    string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                    countB = paras[1].Split(',').Length;
                    bItem = paras[1];
                    type = paras[2];
                }
                count = countA + countB;
                rowCount += count;
                tuple = new Tuple<string, int, string, int, string, int, string>(pierL[i], count, aItem,countA, bItem, countB,type);
                data.Add(tuple);
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                string blockType = "BR2";
                int rowNum = rowCount + 1;

                Table tb = new Table();
                #region  表格

                startPoint = startPoint.Convert3D();
                tb = new Table();
                int colNum = 4;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Columns[i].Width = 6 * 3 * scale;
                }


                //行高
                for (int i = 0; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 5.68 * scale;
                }
                #endregion


                tb.Cells[0, 0].TextString = "Pier No."; //获取i行j列数据
                tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;



                tb.Cells[0, 1].TextString = "Station"; //获取i行j列数据
                tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 1].Contents[0].Rotation = 0;
                tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 1].Contents[0].TextStyleId = id;


                tb.Cells[0, 2].TextString = "H(m)"; //获取i行j列数据
                tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 2].Contents[0].Rotation = 0;
                tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 2].Contents[0].TextStyleId = id;


                tb.Cells[0, 3].TextString = "L(m)"; //获取i行j列数据
                tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 3].Contents[0].Rotation = 0;
                tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 3].Contents[0].TextStyleId = id;

                int num = 1;
                for (int i = 0; i < data.Count; i++)
                {
                    try
                    {
                      
                        blockType = data[i].Item7;
                        string pierNo = data[i].Item1;
                        tb.Cells[num, 0].TextString = pierNo; //获取i行j列数据
                        tb.Cells[num, 0].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[num, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[num, 0].Contents[0].Rotation = 0;
                        tb.Cells[num, 0].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[num, 0].Contents[0].TextStyleId = id;                      
                        tb.MergeCells(CellRange.Create(tb, num, 0, num+ data[i].Item2-1, 0));

                        double zp = 0;
                        double qxkH = 0;

                        DataRow[] drsA = dtA.Select("Pier='" + data[i].Item1 + "'");

                        for (int m = 0; m < data[i].Item4; m++)
                        {
                            drP = dtRes.NewRow();
                            string[] nos = data[i].Item3.Split(',');
                            tb.Cells[num, 1].TextString = "A-" + (m + 1); //获取i行j列数据
                            tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[num, 1].Contents[0].Rotation = 0;
                            tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[num, 1].Contents[0].TextStyleId = id;

                            DataRow[] dr;//= dtA.Select("Pier='" + pierL[i] + "' and (PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%')");
                            if (int.Parse(nos[m]) < 13)
                                dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%')");
                            else
                                dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%' or PlinthNo like '1月" + nos[m] + "日')");
                            string h = "/";
                            double plintBlockDepth = 0.088;
                            zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                            switch (blockType)
                            {
                                case "BR1":
                                    plintBlockDepth = 0.053;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.012;
                                    else if (zp < 0.025)
                                        qxkH = 0.0139;
                                    else if (zp < 0.035)
                                        qxkH = 0.0159;
                                    else if (zp < 0.045)
                                        qxkH = 0.0178;
                                    else if (zp < 0.055)
                                        qxkH = 0.0198;
                                    else
                                        qxkH = 0.0217;
                                    break;
                                case "BR2":
                                    plintBlockDepth = 0.088;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.012;
                                    else if (zp < 0.025)
                                        qxkH = 0.0139;
                                    else if (zp < 0.035)
                                        qxkH = 0.0159;
                                    else if (zp < 0.045)
                                        qxkH = 0.0178;
                                    else if (zp < 0.055)
                                        qxkH = 0.0198;
                                    else
                                        qxkH = 0.0217;
                                    break;
                                case "BR3":
                                    plintBlockDepth = 0.129;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0122;
                                    else if (zp < 0.025)
                                        qxkH = 0.0144;
                                    else if (zp < 0.035)
                                        qxkH = 0.0166;
                                    else if (zp < 0.045)
                                        qxkH = 0.0188;
                                    else if (zp < 0.055)
                                        qxkH = 0.0210;
                                    else
                                        qxkH = 0.0232;
                                    break;
                                case "BR4":
                                    plintBlockDepth = 0.088;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0119;
                                    else if (zp < 0.025)
                                        qxkH = 0.0138;
                                    else if (zp < 0.035)
                                        qxkH = 0.0157;
                                    else if (zp < 0.045)
                                        qxkH = 0.0176;
                                    else if (zp < 0.055)
                                        qxkH = 0.0195;
                                    else
                                        qxkH = 0.0214;
                                    break;
                            }
                           
                            h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + plintBlockDepth + qxkH + 0.3).ToString();

                            h = Math.Round(double.Parse(h) + 0.049, 1).ToString();
                            tb.Cells[num, 2].TextString = h; //获取i行j列数据
                            tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[num, 2].Contents[0].Rotation = 0;
                            tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[num, 2].Contents[0].TextStyleId = id;

                            drP[0] = pierNo;
                            drP[1] = "A-" + (m + 1);
                            drP[2] = h;
                            drP[3] = 0;
                            drP[4] = 0;
                            dtRes.Rows.Add(drP.ItemArray);
                            num++;
                        }

                        DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                        for (int m = 0; m < data[i].Item6; m++)
                        {
                            drP = dtRes.NewRow();
                            string[] nos = data[i].Item5.Split(',');

                            tb.Cells[num, 1].TextString = "B-" + (m + 1); //获取i行j列数据
                            tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[num, 1].Contents[0].Rotation = 0;
                            tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[num, 1].Contents[0].TextStyleId = id;

                            DataRow[] dr;// = dtB.Select("Pier='" + pierL[i] + "' and (PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%')");
                            if (int.Parse(nos[m]) < 13)
                                dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%')");
                            else
                                dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[m] + "-%' or PlinthNo like '" + nos[m] + "月%' or PlinthNo like '1月" + nos[m] + "日')");
                            string h = "/";


                            double plintBlockDepth = 0.088;
                            zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                            switch (blockType)
                            {
                                case "BR1":
                                    plintBlockDepth = 0.053;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.012;
                                    else if (zp < 0.025)
                                        qxkH = 0.0139;
                                    else if (zp < 0.035)
                                        qxkH = 0.0159;
                                    else if (zp < 0.045)
                                        qxkH = 0.0178;
                                    else if (zp < 0.055)
                                        qxkH = 0.0198;
                                    else
                                        qxkH = 0.0217;
                                    break;
                                case "BR2":
                                    plintBlockDepth = 0.088;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.012;
                                    else if (zp < 0.025)
                                        qxkH = 0.0139;
                                    else if (zp < 0.035)
                                        qxkH = 0.0159;
                                    else if (zp < 0.045)
                                        qxkH = 0.0178;
                                    else if (zp < 0.055)
                                        qxkH = 0.0198;
                                    else
                                        qxkH = 0.0217;
                                    break;
                                case "BR3":
                                    plintBlockDepth = 0.129;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0122;
                                    else if (zp < 0.025)
                                        qxkH = 0.0144;
                                    else if (zp < 0.035)
                                        qxkH = 0.0166;
                                    else if (zp < 0.045)
                                        qxkH = 0.0188;
                                    else if (zp < 0.055)
                                        qxkH = 0.0210;
                                    else
                                        qxkH = 0.0232;
                                    break;
                                case "BR4":
                                    plintBlockDepth = 0.088;
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0119;
                                    else if (zp < 0.025)
                                        qxkH = 0.0138;
                                    else if (zp < 0.035)
                                        qxkH = 0.0157;
                                    else if (zp < 0.045)
                                        qxkH = 0.0176;
                                    else if (zp < 0.055)
                                        qxkH = 0.0195;
                                    else
                                        qxkH = 0.0214;
                                    break;
                            }

                            h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + plintBlockDepth + qxkH + 0.3).ToString();

                            h = Math.Round(double.Parse(h) + 0.049, 1).ToString();
                            tb.Cells[num, 2].TextString = h; //获取i行j列数据
                            tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[num, 2].Contents[0].Rotation = 0;
                            tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[num, 2].Contents[0].TextStyleId = id;
                            drP[0] = pierNo;
                            drP[1] = "B-" + (m + 1);
                            drP[2] = h;
                            drP[3] = 0;
                            drP[4] = 0;
                            dtRes.Rows.Add(drP.ItemArray);
                            num++;

                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #endregion

                #region 设置表格值

                #endregion

                #region 表格添加数据

                #endregion



                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion
                //string _blcName = "bufferdepth";
                //db.CopyBlockFromFile(_dwgPath, _blcName);

                //BlockTool.InsertBlockReference(pt4.Convert3D(-200, -10), 30, _blcName, _dwgPath, ref ext, 0);
                //_blcName = "bufferdepth3";
                //db.CopyBlockFromFile(_dwgPath, _blcName);

                //BlockTool.InsertBlockReference(pt4.Convert3D(-200, -150), 1, _blcName, _dwgPath, ref ext, 0);

                string Contents =
                      "Notes:\\P" +                      "1. All dimensions are in m unless otherwise indicated.\\P" +                      "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +                      "3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P" +                      "4. All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P" +
                      "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +                      "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +                      "7.Concrete cover shall be 0.050m for concrete buffer.";
                TextPloter.PrintMultiText(db, ref ext, pt4.Convert3D(-270, -180), Contents, 1, 2.5, 200);
                //_blcName = "Model2";
                //db.CopyBlockFromFile(_dwgPath, _blcName);
                //Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                //Dictionary<string, string> dic = new Dictionary<string, string>();
                //int pierNo = int.Parse(System.Text.RegularExpressions.Regex.Replace(pierName, @"[^0-9]+", "").ToString());
                //string stN = pierName.Replace(pierNo.ToString(), "") + (pierNo - 1);
                //string edN = pierName.Replace(pierNo.ToString(), "") + (pierNo + 1);

                //dic.Add(stN, "string");
                //dicA.Add("NOS", dic);

                //dic = new Dictionary<string, string>();
                //dic.Add(edN, "string");
                //dicA.Add("NOE", dic);

                //BlockTool.InsertBlockReference(pt4.Convert3D(20, -150), 1, _blcName, _dwgPath, dicA, null, ref ext);

                //BlockTool.InsertBlockReference(pt4.Convert3D(45, -90), 1, _blcName, _dwgPath, ref ext, 0);
                Point2d pNote = pt2.Convert2D(0, -2);



                tr.Commit();
                return tb;
            }
        }

        #endregion

        #region T梁
        /// <summary>
        /// 挡板高度绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="scale"></param>
        /// <param name="dwgPath"></param>
        /// <param name="dtRes"></param>
        public static void DrawTBlockDepthTable(Database db, double scale, string dwgPath, ref System.Data.DataTable dtRes, string plinthCoorPath, string blockParaPath, string pierList,  string tAPara, string tBPara, ref string pierdiv,string title="MAINLINE",string tkPath="" )
        {
            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d ext1 = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
            Point2d M1 = CT;
            ext = new Extents2d(M1, M1);
            _dwgPath = dwgPath;

            System.Data.DataTable dt = CVSTools.OpenCSV(plinthCoorPath);

            System.Data.DataTable dtP = new System.Data.DataTable();
            DataView dv0 = dt.DefaultView;
            dt = dv0.ToTable(true, new string[] { "Pier", "Side", "PlinthNo", "East", "North", "Height", "H0", "ZP_ABS" });
            Dictionary<int, List<string>> dic = new Dictionary<int, List<string>>();
            string[] plist = pierList.Split('|');
            for (int i = 0; i < plist.Length; i++)
            {
                List<string> pl = plist[i].Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(',').ToList();
                dic.Add(i + 1, pl);
                pierdiv = pl[0] + "-" + pl[pl.Count - 1];
            }
           
            //List<string> p3 = new List<string>() { "RP-17", "RP-18", "RP-19", "RP-20", "RP-21" };
            //dic.Add(1, p3);
            List<string> pList = new List<string>();
            Dictionary<int, List<string>> dicI = new Dictionary<int, List<string>>();
            int pageno = dic.Count;

            //pageno = iAPara.Split(',').Length;
            //if (pageno < iBPara.Split(',').Length)
            //    pageno = iBPara.Split(',').Length;
            for (int i = 0; i < pageno; i++)
            {

                List<string> pierL = dic[i + 1];
                System.Data.DataTable dtA = new System.Data.DataTable();
                System.Data.DataTable dtB = new System.Data.DataTable();
                dtA = dt.Clone();
                dtB = dt.Clone();
                if (pierL.Count > 0)
                {
                    foreach (string pierName in pierL)
                    {
                        DataRow[] drs = dt.Select("Pier='" + pierName + "'");

                        //DataRow[] drsA = dt.Select("Pier='" + pierName + "' and Side='A' and (PlinthNo like '%-1' or PlinthNo like '%月1日')");
                        DataRow[] drsA = dt.Select("Pier='" + pierName + "' and Side='A' and (PlinthNo like '%-1' or PlinthNo like '%月1日' or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");

                        if (drsA.Length > 0)
                        {
                            foreach (DataRow item in drs)
                            {
                                if(drsA.Contains(item))
                                   dtA.Rows.Add(item.ItemArray);
                            }
                        }
                        DataRow[] drsB = dt.Select("Pier='" + pierName + "' and Side='B' and (PlinthNo like '%-1' or PlinthNo like '%月1日' or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");

                        if (drsB.Length > 0)
                        {
                            foreach (DataRow item in drs)
                            {
                                if (drsB.Contains(item))
                                    dtB.Rows.Add(item.ItemArray);
                            }
                        }
                    }
                }

                Table lasTb = new Table();
                //ext = new Extents2d(M1.Convert2D(420, -297 * i), M1.Convert2D(420, -297 * i));
                //lasTb = DrawingPlinthIBlockDepthTable(db, ref ext, M1.Convert3D(420, -297 * i),
                //    Extensions.curFont, scale, dtA, dtB, dwgPath, pierL, iAPara, iBPara);
                List<Tuple<string, List<double>>> dicList = new List<Tuple<string, List<double>>>(); 
                ext = new Extents2d(M1.Convert2D(0, -297 * i), M1.Convert2D(0, -297 * i));
                //lasTb = DrawingPlinthTBlockDepthTable(db, ref ext, M1.Convert3D(0, 0),
                //    Extensions.curFont, scale, dtA, dtB, dwgPath, pierL, ref dtRes, ref dicList,title, tAPara, tBPara);
                DrawingPlinthTBlockDepthTableNew(db, ref ext, M1.Convert3D(0, 0),
                    Extensions.curFont, scale, dtA, dtB, dwgPath, pierL, ref dtRes, ref dicList, title, tAPara, tBPara);
                Point2d pt = M1.Convert2D(420, -297 * i);
                List<Extents2d> exts = new List<Extents2d>();
                List<Extents2d> extMs = new List<Extents2d>();
                DrawBufferRebars(db,ref exts, ref extMs, pt, dicList,title);
                Common.CreateBufferLayout(db, "T梁挡块钢筋及高度", ext, exts, extMs, scale, 1,0,false, tkPath);
            }
        }

        /// <summary>
        /// T梁挡板高度表格绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="dtA"></param>
        /// <param name="dtB"></param>
        /// <param name="_dwgPath"></param>
        /// <param name="pierL"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static Table DrawingPlinthTBlockDepthTable(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable dtA, System.Data.DataTable dtB, string _dwgPath, List<string> pierL, ref System.Data.DataTable dt, ref List<Tuple<string, List<double>>> dicList,string title, string TAPara = "", string TBPara = "")
        {
            List<string> aParas = TAPara.Split('|').ToList();
            List<string> bParas = TBPara.Split('|').ToList();
            Tuple<string, int, string, int, string, int, string> tuple;
            List<Tuple<string, int, string, int, string, int, string>> data = new List<Tuple<string, int, string, int, string, int, string>>();
            int rowCount = 0;
            for (int i = 0; i < pierL.Count; i++)
            {
               
                int count = 0;
                int countA = 0;
                int countB = 0;
                string aItem = "";
                string bItem = "";
                string type = "";
                if (TAPara.Contains(pierL[i]))
                {
                    //pierList.Add(pierL[i]);
                    string para = aParas.Find(item => item.Contains(pierL[i]));
                    string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                   
                    if(string.IsNullOrWhiteSpace(paras[1]))
                    {
                        countA =0;
                        aItem = "";
                    }
                    else
                    {
                        countA = paras[1].Split(',').Length;
                        aItem = paras[1];
                    }
                    //type = paras[2];
                }
                else
                {
                    DataRow[] drsA = dtA.Select("Pier='" + pierL[i] + "'");
                    countA = 4;
                    aItem =(drsA.Length) + "," + (drsA.Length - 1) + ",2,1";
                    if(title== "RAMP MOHAKHALI EX-1")
                        aItem ="1,2,"+ (drsA.Length-1) + "," + (drsA.Length);
                }
                if (TBPara.Contains(pierL[i]))
                {
                    //if (!pierList.Contains(pierL[i]))
                    //    pierList.Add(pierL[i]);
                    string para = bParas.Find(item => item.Contains(pierL[i]));
                    string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                    if (string.IsNullOrWhiteSpace(paras[1]))
                    {
                        countB = 0;
                        bItem = "";
                    }
                    else
                    {
                        countB = paras[1].Split(',').Length;
                        bItem = paras[1];
                    }
                  
                    //type = paras[2];
                }
                else
                {
                    DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                    countB = 4;
                    bItem = (drsB.Length) + "," + (drsB.Length - 1) + ",2,1";
                    if (title == "RAMP MOHAKHALI EX-1")
                        bItem = "1,2," + (drsB.Length - 1) + "," + (drsB.Length);
                }
                count = countA;
                if (countA< countB)
                   count =  countB;
                rowCount += count;
                tuple = new Tuple<string, int, string, int, string, int, string>(pierL[i], count, aItem, countA, bItem, countB, type);
                data.Add(tuple);
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                int rowNum = rowCount + 1;
                //if(rowCount>8)
                Table tb = new Table();
                #region  表格

                startPoint = startPoint.Convert3D();
                tb = new Table();
                int colNum = 5;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Columns[i].Width = 6 * 3 * scale;
                }


                //行高
                for (int i = 0; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 5.68 * scale;
                }
                #endregion


                tb.Cells[0, 0].TextString = "Pier No."; //获取i行j列数据
                tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;



                tb.Cells[0, 1].TextString = "Station"; //获取i行j列数据
                tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 1].Contents[0].Rotation = 0;
                tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 1].Contents[0].TextStyleId = id;


                tb.Cells[0, 2].TextString = "H(m)"; //获取i行j列数据
                tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 2].Contents[0].Rotation = 0;
                tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 2].Contents[0].TextStyleId = id;


                tb.Cells[0, 3].TextString = "Station"; //获取i行j列数据
                tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 3].Contents[0].Rotation = 0;
                tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 3].Contents[0].TextStyleId = id;



                tb.Cells[0, 4].TextString = "H(m)"; //获取i行j列数据
                tb.Cells[0, 4].Contents[0].TextHeight = 2 * scale;
                tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 4].Contents[0].Rotation = 0;
                tb.Cells[0, 4].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 4].Contents[0].TextStyleId = id;
                int num = 1;
                int no = 1;
                for (int i = 0; i < data.Count; i++)
                {
                    List<double> blockDepthList = new List<double>();
                    try
                    {
                        string pierNo = data[i].Item1;
                        tb.Cells[num, 0].TextString = pierNo; //获取i行j列数据
                        tb.Cells[num, 0].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[num, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[num, 0].Contents[0].Rotation = 0;
                        tb.Cells[num, 0].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[num, 0].Contents[0].TextStyleId = id;
                        //tb.MergeCells(CellRange.Create(tb, i * 4 + 1, 0, i * 4 + 4, 0));
                        tb.MergeCells(CellRange.Create(tb, num, 0, num + data[i].Item2 - 1, 0));

                        double zp = 0;
                        double qxkH = 0;

                        DataRow[] drsA = dtA.Select("Pier='" + pierL[i] + "'");
                        int ma = 0;
                        int mb = 0;
                        for (int n = 0; n < data[i].Item2; n++)
                        {

                            if (n < data[i].Item4)
                            {

                                string[] nos = data[i].Item3.Split(',');
                                tb.Cells[num, 1].TextString = "A-" + (ma + 1); //获取i行j列数据
                                tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 1].Contents[0].Rotation = 0;
                                tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 1].Contents[0].TextStyleId = id;

                                DataRow[] dr;
                                if (int.Parse(nos[ma])<13)
                                    dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[ma] + "-%' or PlinthNo like '" + nos[ma] + "月%')");
                                else
                                    dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[ma] + "-%' or PlinthNo like '" + nos[ma] + "月%' or PlinthNo like '1月" + nos[ma] + "日')");
                                string h = "/";

                                zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                                if (zp == 0)
                                    qxkH = 0;
                                else if (zp < 0.015)
                                    qxkH = 0.0122;
                                else if (zp < 0.025)
                                    qxkH = 0.0144;
                                else if (zp < 0.035)
                                    qxkH = 0.0166;
                                else if (zp < 0.045)
                                    qxkH = 0.0188;
                                else if (zp < 0.055)
                                    qxkH = 0.0210;
                                else
                                    qxkH = 0.0232;
                                h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + 0.089 + qxkH + 0.3).ToString("0.000");

                                blockDepthList.Add(double.Parse(h));
                                tb.Cells[num, 2].TextString = h; //获取i行j列数据
                                tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 2].Contents[0].Rotation = 0;
                                tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 2].Contents[0].TextStyleId = id;

                                System.Data.DataRow drR = dt.NewRow();
                                drR[0] = no;
                                drR[1] = pierNo;
                                drR[2] = 0.089;
                                drR[3] = "A";
                                drR[4] = "A-" + (ma + 1);
                                drR[5] = double.Parse(dr[0]["Height"].ToString()).ToString("0.000");
                                drR[6] = zp;
                                drR[7] = qxkH;
                                drR[8] = h;
                                dt.Rows.Add(drR);
                                ma++;
                                no++;
                            }
                            else
                            {
                              
                                    string[] nos = data[i].Item3.Split(',');
                                    tb.Cells[num, 1].TextString = "/"; //获取i行j列数据
                                    tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 1].Contents[0].Rotation = 0;
                                    tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 1].Contents[0].TextStyleId = id;

                                    string h = "/";

                                    tb.Cells[num, 2].TextString = h; //获取i行j列数据
                                    tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 2].Contents[0].Rotation = 0;
                                    tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 2].Contents[0].TextStyleId = id;

                            }

                            DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                            if (n < data[i].Item6)
                            {

                                string[] nos = data[i].Item5.Split(',');
                                tb.Cells[num, 3].TextString = "B-" + (mb + 1); //获取i行j列数据
                                tb.Cells[num, 3].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 3].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 3].Contents[0].Rotation = 0;
                                tb.Cells[num, 3].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 3].Contents[0].TextStyleId = id;

                                //DataRow[] dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%')");
                                DataRow[] dr;
                                if (int.Parse(nos[mb]) < 13)
                                    dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%')");
                                else
                                    dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%' or PlinthNo like '1月" + nos[mb] + "日' )");
                                string h = "/";

                                zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                                if (zp == 0)
                                    qxkH = 0;
                                else if (zp < 0.015)
                                    qxkH = 0.0122;
                                else if (zp < 0.025)
                                    qxkH = 0.0144;
                                else if (zp < 0.035)
                                    qxkH = 0.0166;
                                else if (zp < 0.045)
                                    qxkH = 0.0188;
                                else if (zp < 0.055)
                                    qxkH = 0.0210;
                                else
                                    qxkH = 0.0232;
                                h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + 0.089 + qxkH + 0.3).ToString("0.000");

                                blockDepthList.Add(double.Parse(h));
                                tb.Cells[num, 4].TextString = h; //获取i行j列数据
                                tb.Cells[num, 4].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 4].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 4].Contents[0].Rotation = 0;
                                tb.Cells[num, 4].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 4].Contents[0].TextStyleId = id;


                                System.Data.DataRow drR = dt.NewRow();
                                drR[0] = no;
                                drR[1] = pierNo;
                                drR[2] = 0.089;
                                drR[3] = "B";
                                drR[4] = "B-" + (mb + 1);
                                drR[5] = double.Parse(dr[0]["Height"].ToString()).ToString("0.000");
                                drR[6] = zp;
                                drR[7] = qxkH;
                                drR[8] = h;
                                dt.Rows.Add(drR);
                                mb++;
                                no++;
                            }
                            else
                            {
                                string[] nos = data[i].Item5.Split(',');
                                tb.Cells[num, 3].TextString = "/"; //获取i行j列数据
                                tb.Cells[num, 3].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 3].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 3].Contents[0].Rotation = 0;
                                tb.Cells[num, 3].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 3].Contents[0].TextStyleId = id;

                                string h = "/";

                                tb.Cells[num, 4].TextString = h; //获取i行j列数据
                                tb.Cells[num, 4].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[num, 4].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[num, 4].Contents[0].Rotation = 0;
                                tb.Cells[num, 4].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[num, 4].Contents[0].TextStyleId = id;

                            }
                            num++;
                          
                        }
                        Tuple<string, List<double>> tu = new Tuple<string, List<double>>(pierL[i], blockDepthList);
                        dicList.Add(tu);
                    }
                    catch (Exception ex)
                    {

                    }
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #endregion

                #region 设置表格值

                #endregion

                #region 表格添加数据

                #endregion



                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                string _blcName = "TBuffer0";
                db.CopyBlockFromFile(_dwgPath, _blcName);

                BlockTool.InsertBlockReference(pt4.Convert3D(-350, -185), 50, _blcName, _dwgPath, ref ext, 0);

                _blcName = "TBeam0";
                db.CopyBlockFromFile(_dwgPath, _blcName);

                BlockTool.InsertBlockReference(pt2.Convert3D(tb.Width*0.5, -10), 1, _blcName, _dwgPath, ref ext, 0);

                string Contents =
                      "Notes:\\P" +                      "1. All dimensions are in m unless otherwise indicated.\\P" +                      "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +                      "3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P" +                      "4. All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P" +
                      "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +                      "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +                      "7.Concrete cover shall be 0.050m for concrete buffer.";
                TextPloter.PrintMultiText(db, ref ext, pt4.Convert3D(-330, -185), Contents, 1, 2.5, 200);
                //_blcName = "Model2";
                //db.CopyBlockFromFile(_dwgPath, _blcName);
                //Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                //Dictionary<string, string> dic = new Dictionary<string, string>();
                //int pierNo = int.Parse(System.Text.RegularExpressions.Regex.Replace(pierName, @"[^0-9]+", "").ToString());
                //string stN = pierName.Replace(pierNo.ToString(), "") + (pierNo - 1);
                //string edN = pierName.Replace(pierNo.ToString(), "") + (pierNo + 1);

                //dic.Add(stN, "string");
                //dicA.Add("NOS", dic);

                //dic = new Dictionary<string, string>();
                //dic.Add(edN, "string");
                //dicA.Add("NOE", dic);

                //BlockTool.InsertBlockReference(pt4.Convert3D(20, -150), 1, _blcName, _dwgPath, dicA, null, ref ext);

                //BlockTool.InsertBlockReference(pt4.Convert3D(45, -90), 1, _blcName, _dwgPath, ref ext, 0);
                Point2d pNote = pt2.Convert2D(0, -2);



                tr.Commit();
                return tb;
            }
        }
        public static void DrawingPlinthTBlockDepthTableNew(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable dtA, System.Data.DataTable dtB, string _dwgPath, List<string> pierL, ref System.Data.DataTable dt, ref List<Tuple<string, List<double>>> dicList, string title, string TAPara = "", string TBPara = "")
        {
            List<string> aParas = TAPara.Split('|').ToList();
            List<string> bParas = TBPara.Split('|').ToList();
            Tuple<string, int, string, int, string, int, string> tuple;
            List<Tuple<int, List<Tuple<string, int, string, int, string, int, string>>>> datas = new List<Tuple<int, List<Tuple<string, int, string, int, string, int, string>>>>();
            List<Tuple<string, int, string, int, string, int, string>> data = new List<Tuple<string, int, string, int, string, int, string>>();
            int rowCount = 0;
            for (int i = 0; i < pierL.Count; i++)
            {
                if (pierL.Count > 7)
                {
                    if (i <= (int)(pierL.Count / 2))
                    {
                        int count = 0;
                        int countA = 0;
                        int countB = 0;
                        string aItem = "";
                        string bItem = "";
                        string type = "";
                        if (TAPara.Contains(pierL[i]))
                        {
                            //pierList.Add(pierL[i]);
                            string para = aParas.Find(item => item.Contains(pierL[i]));
                            string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');

                            if (string.IsNullOrWhiteSpace(paras[1]))
                            {
                                countA = 0;
                                aItem = "";
                            }
                            else
                            {
                                countA = paras[1].Split(',').Length;
                                aItem = paras[1];
                            }
                            //type = paras[2];
                        }
                        else
                        {
                            DataRow[] drsA = dtA.Select("Pier='" + pierL[i] + "'");
                            countA = 4;
                            aItem = (drsA.Length) + "," + (drsA.Length - 1) + ",2,1";
                            if (title == "RAMP MOHAKHALI EX-1")
                                aItem = "1,2," + (drsA.Length - 1) + "," + (drsA.Length);
                        }
                        if (TBPara.Contains(pierL[i]))
                        {
                            //if (!pierList.Contains(pierL[i]))
                            //    pierList.Add(pierL[i]);
                            string para = bParas.Find(item => item.Contains(pierL[i]));
                            string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                            if (string.IsNullOrWhiteSpace(paras[1]))
                            {
                                countB = 0;
                                bItem = "";
                            }
                            else
                            {
                                countB = paras[1].Split(',').Length;
                                bItem = paras[1];
                            }

                            //type = paras[2];
                        }
                        else
                        {
                            DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                            countB = 4;
                            bItem = (drsB.Length) + "," + (drsB.Length - 1) + ",2,1";
                            if (title == "RAMP MOHAKHALI EX-1")
                                bItem = "1,2," + (drsB.Length - 1) + "," + (drsB.Length);
                        }
                        count = countA;
                        if (countA < countB)
                            count = countB;
                        rowCount += count;
                        tuple = new Tuple<string, int, string, int, string, int, string>(pierL[i], count, aItem, countA, bItem, countB, type);
                        data.Add(tuple);
                        if (i == (int)(pierL.Count / 2))
                        {
                            Tuple<int, List<Tuple<string, int, string, int, string, int, string>>> tp = new Tuple<int, List<Tuple<string, int, string, int, string, int, string>>>(rowCount, data);
                            datas.Add(tp);
                            rowCount = 0;
                            data = new List<Tuple<string, int, string, int, string, int, string>>();
                        }
                    }
                    else
                    {
                        int count = 0;
                        int countA = 0;
                        int countB = 0;
                        string aItem = "";
                        string bItem = "";
                        string type = "";
                        if (TAPara.Contains(pierL[i]))
                        {
                            //pierList.Add(pierL[i]);
                            string para = aParas.Find(item => item.Contains(pierL[i]));
                            string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');

                            if (string.IsNullOrWhiteSpace(paras[1]))
                            {
                                countA = 0;
                                aItem = "";
                            }
                            else
                            {
                                countA = paras[1].Split(',').Length;
                                aItem = paras[1];
                            }
                            //type = paras[2];
                        }
                        else
                        {
                            DataRow[] drsA = dtA.Select("Pier='" + pierL[i] + "'");
                            countA = 4;
                            aItem = (drsA.Length) + "," + (drsA.Length - 1) + ",2,1";
                            if (title == "RAMP MOHAKHALI EX-1")
                                aItem = "1,2," + (drsA.Length - 1) + "," + (drsA.Length);
                        }
                        if (TBPara.Contains(pierL[i]))
                        {
                            //if (!pierList.Contains(pierL[i]))
                            //    pierList.Add(pierL[i]);
                            string para = bParas.Find(item => item.Contains(pierL[i]));
                            string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                            if (string.IsNullOrWhiteSpace(paras[1]))
                            {
                                countB = 0;
                                bItem = "";
                            }
                            else
                            {
                                countB = paras[1].Split(',').Length;
                                bItem = paras[1];
                            }

                            //type = paras[2];
                        }
                        else
                        {
                            DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                            countB = 4;
                            bItem = (drsB.Length) + "," + (drsB.Length - 1) + ",2,1";
                            if (title == "RAMP MOHAKHALI EX-1")
                                bItem = "1,2," + (drsB.Length - 1) + "," + (drsB.Length);
                        }
                        count = countA;
                        if (countA < countB)
                            count = countB;
                        rowCount += count;
                        tuple = new Tuple<string, int, string, int, string, int, string>(pierL[i], count, aItem, countA, bItem, countB, type);
                        data.Add(tuple);
                    }
                }
                else
                {
                    int count = 0;
                    int countA = 0;
                    int countB = 0;
                    string aItem = "";
                    string bItem = "";
                    string type = "";
                    if (TAPara.Contains(pierL[i]))
                    {
                        //pierList.Add(pierL[i]);
                        string para = aParas.Find(item => item.Contains(pierL[i]));
                        string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');

                        if (string.IsNullOrWhiteSpace(paras[1]))
                        {
                            countA = 0;
                            aItem = "";
                        }
                        else
                        {
                            countA = paras[1].Split(',').Length;
                            aItem = paras[1];
                        }
                        //type = paras[2];
                    }
                    else
                    {
                        DataRow[] drsA = dtA.Select("Pier='" + pierL[i] + "'");
                        countA = 4;
                        aItem = (drsA.Length) + "," + (drsA.Length - 1) + ",2,1";
                        if (title == "RAMP MOHAKHALI EX-1")
                            aItem = "1,2," + (drsA.Length - 1) + "," + (drsA.Length);
                    }
                    if (TBPara.Contains(pierL[i]))
                    {
                        //if (!pierList.Contains(pierL[i]))
                        //    pierList.Add(pierL[i]);
                        string para = bParas.Find(item => item.Contains(pierL[i]));
                        string[] paras = para.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
                        if (string.IsNullOrWhiteSpace(paras[1]))
                        {
                            countB = 0;
                            bItem = "";
                        }
                        else
                        {
                            countB = paras[1].Split(',').Length;
                            bItem = paras[1];
                        }

                        //type = paras[2];
                    }
                    else
                    {
                        DataRow[] drsB = dtB.Select("Pier='" + pierL[i] + "'");
                        countB = 4;
                        bItem = (drsB.Length) + "," + (drsB.Length - 1) + ",2,1";
                        if (title == "RAMP MOHAKHALI EX-1")
                            bItem = "1,2," + (drsB.Length - 1) + "," + (drsB.Length);
                    }
                    count = countA;
                    if (countA < countB)
                        count = countB;
                    rowCount += count;
                    tuple = new Tuple<string, int, string, int, string, int, string>(pierL[i], count, aItem, countA, bItem, countB, type);
                    data.Add(tuple);
                }
                if (i == pierL.Count - 1)
                {
                    Tuple<int, List<Tuple<string, int, string, int, string, int, string>>> tp = new Tuple<int, List<Tuple<string, int, string, int, string, int, string>>>(rowCount, data);
                    datas.Add(tp);
                }
            }
            Table tb = new Table();
            double height = 0;
            for (int m = 0; m < datas.Count; m++)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId id;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    id = st[txtStyle];

                    int rowNum = datas[m].Item1 + 1;
                    double width = tb.Width;
                    tb = new Table();
                    #region  表格

                    startPoint = startPoint.Convert3D(width + 5);
                    tb = new Table();
                    int colNum = 5;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Columns[i].Width = 6 * 3 * scale;
                    }


                    //行高
                    for (int i = 0; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 5.68 * scale;
                    }
                    #endregion


                    tb.Cells[0, 0].TextString = "Pier No."; //获取i行j列数据
                    tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;



                    tb.Cells[0, 1].TextString = "Station"; //获取i行j列数据
                    tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 1].Contents[0].Rotation = 0;
                    tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 1].Contents[0].TextStyleId = id;


                    tb.Cells[0, 2].TextString = "H(m)"; //获取i行j列数据
                    tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 2].Contents[0].Rotation = 0;
                    tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 2].Contents[0].TextStyleId = id;


                    tb.Cells[0, 3].TextString = "Station"; //获取i行j列数据
                    tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 3].Contents[0].Rotation = 0;
                    tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 3].Contents[0].TextStyleId = id;



                    tb.Cells[0, 4].TextString = "H(m)"; //获取i行j列数据
                    tb.Cells[0, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 4].Contents[0].Rotation = 0;
                    tb.Cells[0, 4].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 4].Contents[0].TextStyleId = id;
                    int num = 1;
                    int no = 1;
                    data = datas[m].Item2;
                    for (int i = 0; i < data.Count; i++)
                    {
                        List<double> blockDepthList = new List<double>();
                        try
                        {
                            string pierNo = data[i].Item1;
                            tb.Cells[num, 0].TextString = pierNo; //获取i行j列数据
                            tb.Cells[num, 0].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[num, 0].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[num, 0].Contents[0].Rotation = 0;
                            tb.Cells[num, 0].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[num, 0].Contents[0].TextStyleId = id;
                            //tb.MergeCells(CellRange.Create(tb, i * 4 + 1, 0, i * 4 + 4, 0));
                            tb.MergeCells(CellRange.Create(tb, num, 0, num + data[i].Item2 - 1, 0));

                            double zp = 0;
                            double qxkH = 0;

                            DataRow[] drsA = dtA.Select("Pier='" + data[i].Item1 + "'");
                            int ma = 0;
                            int mb = 0;
                            for (int n = 0; n < data[i].Item2; n++)
                            {

                                if (n < data[i].Item4)
                                {

                                    string[] nos = data[i].Item3.Split(',');
                                    tb.Cells[num, 1].TextString = "A-" + (ma + 1); //获取i行j列数据
                                    tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 1].Contents[0].Rotation = 0;
                                    tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 1].Contents[0].TextStyleId = id;

                                    DataRow[] dr;
                                    if (int.Parse(nos[ma]) < 13)
                                        dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[ma] + "-%' or PlinthNo like '" + nos[ma] + "月%')");
                                    else
                                        dr = dtA.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[ma] + "-%' or PlinthNo like '" + nos[ma] + "月%' or PlinthNo like '1月" + nos[ma] + "日')");
                                    string h = "/";

                                    zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0122;
                                    else if (zp < 0.025)
                                        qxkH = 0.0144;
                                    else if (zp < 0.035)
                                        qxkH = 0.0166;
                                    else if (zp < 0.045)
                                        qxkH = 0.0188;
                                    else if (zp < 0.055)
                                        qxkH = 0.0210;
                                    else
                                        qxkH = 0.0232;
                                    h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + 0.089 + qxkH + 0.3).ToString("0.000");

                                    blockDepthList.Add(double.Parse(h));
                                    tb.Cells[num, 2].TextString = h; //获取i行j列数据
                                    tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 2].Contents[0].Rotation = 0;
                                    tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 2].Contents[0].TextStyleId = id;

                                    System.Data.DataRow drR = dt.NewRow();
                                    drR[0] = no;
                                    drR[1] = pierNo;
                                    drR[2] = 0.089;
                                    drR[3] = "A";
                                    drR[4] = "A-" + (ma + 1);
                                    drR[5] = double.Parse(dr[0]["Height"].ToString()).ToString("0.000");
                                    drR[6] = zp;
                                    drR[7] = qxkH;
                                    drR[8] = h;
                                    dt.Rows.Add(drR);
                                    ma++;
                                    no++;
                                }
                                else
                                {

                                    string[] nos = data[i].Item3.Split(',');
                                    tb.Cells[num, 1].TextString = "/"; //获取i行j列数据
                                    tb.Cells[num, 1].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 1].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 1].Contents[0].Rotation = 0;
                                    tb.Cells[num, 1].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 1].Contents[0].TextStyleId = id;

                                    string h = "/";

                                    tb.Cells[num, 2].TextString = h; //获取i行j列数据
                                    tb.Cells[num, 2].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 2].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 2].Contents[0].Rotation = 0;
                                    tb.Cells[num, 2].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 2].Contents[0].TextStyleId = id;

                                }

                                DataRow[] drsB = dtB.Select("Pier='" + data[i].Item1 + "'");
                                if (n < data[i].Item6)
                                {

                                    string[] nos = data[i].Item5.Split(',');
                                    tb.Cells[num, 3].TextString = "B-" + (mb + 1); //获取i行j列数据
                                    tb.Cells[num, 3].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 3].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 3].Contents[0].Rotation = 0;
                                    tb.Cells[num, 3].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 3].Contents[0].TextStyleId = id;

                                    //DataRow[] dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%')");
                                    DataRow[] dr;
                                    if (int.Parse(nos[mb]) < 13)
                                        dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%')");
                                    else
                                        dr = dtB.Select("Pier='" + pierL[i] + "' and ( PlinthNo like '" + nos[mb] + "-%' or PlinthNo like '" + nos[mb] + "月%' or PlinthNo like '1月" + nos[mb] + "日' )");
                                    string h = "/";

                                    zp = double.Parse(dr[0]["ZP_ABS"].ToString());
                                    if (zp == 0)
                                        qxkH = 0;
                                    else if (zp < 0.015)
                                        qxkH = 0.0122;
                                    else if (zp < 0.025)
                                        qxkH = 0.0144;
                                    else if (zp < 0.035)
                                        qxkH = 0.0166;
                                    else if (zp < 0.045)
                                        qxkH = 0.0188;
                                    else if (zp < 0.055)
                                        qxkH = 0.0210;
                                    else
                                        qxkH = 0.0232;
                                    h = (double.Parse(double.Parse(dr[0]["Height"].ToString()).ToString("0.000")) + 0.089 + qxkH + 0.3).ToString("0.000");

                                    blockDepthList.Add(double.Parse(h));
                                    tb.Cells[num, 4].TextString = h; //获取i行j列数据
                                    tb.Cells[num, 4].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 4].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 4].Contents[0].Rotation = 0;
                                    tb.Cells[num, 4].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 4].Contents[0].TextStyleId = id;


                                    System.Data.DataRow drR = dt.NewRow();
                                    drR[0] = no;
                                    drR[1] = pierNo;
                                    drR[2] = 0.089;
                                    drR[3] = "B";
                                    drR[4] = "B-" + (mb + 1);
                                    drR[5] = double.Parse(dr[0]["Height"].ToString()).ToString("0.000");
                                    drR[6] = zp;
                                    drR[7] = qxkH;
                                    drR[8] = h;
                                    dt.Rows.Add(drR);
                                    mb++;
                                    no++;
                                }
                                else
                                {
                                    string[] nos = data[i].Item5.Split(',');
                                    tb.Cells[num, 3].TextString = "/"; //获取i行j列数据
                                    tb.Cells[num, 3].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 3].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 3].Contents[0].Rotation = 0;
                                    tb.Cells[num, 3].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 3].Contents[0].TextStyleId = id;

                                    string h = "/";

                                    tb.Cells[num, 4].TextString = h; //获取i行j列数据
                                    tb.Cells[num, 4].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[num, 4].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[num, 4].Contents[0].Rotation = 0;
                                    tb.Cells[num, 4].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[num, 4].Contents[0].TextStyleId = id;

                                }
                                num++;

                            }
                            Tuple<string, List<double>> tu = new Tuple<string, List<double>>(data[i].Item1, blockDepthList);
                            dicList.Add(tu);
                        }
                        catch (Exception ex)
                        {

                        }
                    }

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                    #endregion

                    #region 设置表格值

                    #endregion

                    #region 表格添加数据

                    #endregion



                    #region  边框粗线设置
                    List<Point2d> pList = new List<Point2d>();
                    Point2d pt1 = startPoint.Convert2D();
                    pList.Add(pt1);
                    Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                    pList.Add(pt2);
                    Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                    pList.Add(pt3);
                    Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                    pList.Add(pt4);
                    PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                    #endregion
                    if (tb.Height > height)
                        height = tb.Height;
                    tr.Commit();
                }
            }

            string _blcName = "TBuffer0";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            if (datas.Count == 1)
                BlockTool.InsertBlockReference(startPoint.Convert3D(-210, -height - 40), 50, _blcName, _dwgPath, ref ext, 0);
            else
                BlockTool.InsertBlockReference(startPoint.Convert3D(-tb.Width - 210, -height-40), 50, _blcName, _dwgPath, ref ext, 0);
            _blcName = "TBeam0";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            if (datas.Count == 1)
                BlockTool.InsertBlockReference(startPoint.Convert3D(tb.Width * 0.5, -height - 10), 1, _blcName, _dwgPath, ref ext, 0);
            else
                BlockTool.InsertBlockReference(startPoint.Convert3D( - 5 * 0.5, -height - 10), 1, _blcName, _dwgPath, ref ext, 0);
            string Contents =
                  "Notes:\\P" +
                  "1. All dimensions are in m unless otherwise indicated.\\P" +
                  "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
                  "3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P" +
                  "4. All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P" +
                  "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +
                  "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
                  "7.Concrete cover shall be 0.050m for concrete buffer.";
            if (datas.Count == 1)
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-190, -height - 30), Contents, 1, 2.5, 200);
            else
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-tb.Width - 190, -height - 30), Contents, 1, 2.5, 200);

            //Point2d pNote = pt2.Convert2D(0, -2);





        }

        #endregion

        #region T梁钢筋
        public static void DrawBufferRebars(Database db, ref List<Extents2d> exts, ref List<Extents2d> extMs, Point2d pt, List<Tuple<string, List<double>>> dicList,string title)
        {
            BufferReber ret = new BufferReber("", "", 0, 0);
            ret.SetRebarList();
            List<Tuple<string, RebarCollection>> bufferRebarTuples = ret.bufferRebarTuples;
            List<Tuple<string,double, double, List<Tuple<Tuple<string, RebarCollection>, double>>>> tupleLst = new List<Tuple<string, double, double, List<Tuple<Tuple<string, RebarCollection>, double>>>>();
            #region 参考量表
            //dicList = new List<Tuple<string, List<double>>>();
            //List<double> lstT = new List<double>();
            //for (int i = 3; i < 19; i++)
            //{
            //    lstT.Add(i * 0.1 + 0.01);
            //}
            //Tuple<string, List<double>> l = new Tuple<string, List<double>>("T梁参考", lstT);
            //dicList.Add(l);
            #endregion

            for (int i = 0; i < dicList.Count; i++)
            {
                Tuple<string, List<double>> tuple = dicList[i];
                string pierName = tuple.Item1;
                List<double> depthLst = tuple.Item2;
                List<Tuple<Tuple<string, RebarCollection>,double>> tuPList = new List<Tuple<Tuple<string, RebarCollection>, double>>();
                double volumn = 0;
                for (int n = 3; n < 30; n++)
                {
                  
                    List<double> lst= depthLst.FindAll(o => (o > (n * 0.1) && o <= ((n + 1) * 0.1)));
                    if(lst.Count>0)
                    {
                        foreach(double h in lst)
                        {
                            volumn += 0.5 * 0.25 * h;
                        }
                        Tuple<string, RebarCollection> tu = bufferRebarTuples.Find(o => o.Item1 == n * 0.1 + "<H<=" + (n + 1) * 0.1);
                        Tuple<Tuple<string, RebarCollection>, double> tuItem = new Tuple<Tuple<string, RebarCollection>, double>(tu, lst.Count);
                        tuPList.Add(tuItem);
                    }
                }
                if (tuPList.Count > 0)
                {
                    Tuple<string, double, double, List<Tuple<Tuple<string, RebarCollection>, double>>> tuR = new Tuple<string, double, double, List<Tuple<Tuple<string, RebarCollection>, double>>>(pierName, volumn, depthLst.Count, tuPList);
                    tupleLst.Add(tuR);
                }
            }
            if(tupleLst.Count>0)
            {
                for (int i = 0; i < tupleLst.Count; i++)
                {
                    Extents2d ext = new Extents2d(pt.Convert2D(420*i), pt.Convert2D(420 * i));
                    Table lasTb = DrawColumnTable(db, ref ext, pt.Convert3D(420 * i), Extensions.curFont, 1, tupleLst[i], 0, title);
                    exts.Add(ext);

                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                   Point3d  ptM = pt.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * 1);
                    Extents2d extMerge = new Extents2d(ptM.Convert2D(), ptM.Convert2D());
                    Table tb = DrawMergeColumnTable(db, tupleLst[i],  ref extMerge, ptM, mergeList,
                        Extensions.curFont, 1);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("QUANTITIES OF CONCRETE BUFFER FOR {0} OF {1} ({2} CONCRETE BUFFER)", tupleLst[i].Item1, title, tupleLst[i].Item3);

                        TextPloter.PrintScaleDoubleSideText(db, ptM.Convert2D(width / 2, 4 * 1), 3, str1, "", ref extMerge, 1, Extensions.curFont);
                    }
                    extMs.Add(extMerge);
                }
            }
        }

        public static Table DrawColumnTable(Database db, ref Extents2d ext, Point3d startPoint,
 string txtStyle, double scale, Tuple<string, double, double, List<Tuple<Tuple<string, RebarCollection>, double>>> tuple, int pageCount = 0, string title = "MAINLINE")
        {
            int rowNum = 2+ tuple.Item4.Count*3;
            List<Tuple<Tuple<string, RebarCollection>, double>> tuP= tuple.Item4;
           
            string pierName= tuple.Item1;
            int bufferCount= (int)tuple.Item3;
           //表格表头
           List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;
            int cuRCount = 0;//当前页行高小于块高度的数量
            int curAllRow = 0;//当前页行数
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                
            
                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF CONCRETE BUFFER  FOR {0} OF " + title + "({1} CONCRETE BUFFER)",
                       pierName, bufferCount);
               
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tuP.Count > 0)
                {
                    for(int i=0;i< tuple.Item4.Count;i++)
                    {
                        RebarCollection tbValue = tuP[i].Item1.Item2;
                        for (int m = 0; m < tbValue.Count; m++)
                        {
                            try
                            {
                                //
                                string value = "";
                                int n = 0;
                                value = tbValue[m].MBarMark.ToString();
                                if (tbValue[m].SBarMark != 0)
                                    value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                else
                                    value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                                tb.Cells[i*3+m + 2, n].TextString = value+"\\P" + tuP[i].Item1.Item1; //获取i行j列数据
                                tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;

                                n++;
                                tb.Cells[i*3+m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                                tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;

                                //Formula
                                n = n + 2;
                                tb.Cells[i*3+m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                                tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;

                                //R
                                n++;
                                value = "";
                                if (tbValue[m].R != 0)
                                    value = tbValue[m].R.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //d
                                n++;
                                value = "";
                                if (tbValue[m].Diameter != 0)
                                {
                                    value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                                }
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //r
                                n++;
                                value = "";
                                if (tbValue[m].r != 0)
                                    value = tbValue[m].r.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //h
                                n++;
                                value = "";
                                if (tbValue[m].h != 0)
                                    value = tbValue[m].h.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //n
                                n++;
                                value = "";
                                if (tbValue[m].n != 0)
                                    value = tbValue[m].n.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //Lx
                                n++;
                                value = "";
                                if (tbValue[m].Lx != 0)
                                    value = tbValue[m].Lx.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //A
                                n++;
                                value = "";
                                if (tbValue[m].A != 0)
                                    value = tbValue[m].A.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //B
                                n++;
                                value = "";
                                if (tbValue[m].B != 0)
                                    value = tbValue[m].B.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //C
                                n++;
                                value = "";
                                if (tbValue[m].C != 0)
                                    value = tbValue[m].C.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //D
                                n++;
                                value = "";
                                if (tbValue[m].D != 0)
                                    value = tbValue[m].D.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }
                                //E
                                n++;
                                value = "";
                                if (tbValue[m].E != 0)
                                    value = tbValue[m].E.ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }
                                //Quantity
                                n++;
                                value = "";
                                if (tbValue[m].Quantity != 0)
                                    value = (tbValue[m].Quantity* tuP[i].Item2).ToString();
                                tb.Cells[i*3+m + 2, n].TextString = value; //获取i行j列数据
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //Length
                                n++;
                                value = "";
                                if (tbValue[m].Length != 0)
                                    value = (tbValue[m].Length * tuP[i].Item2).ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //TotalLength
                                n++;
                                value = "";
                                if (tbValue[m].TotalLength != 0)
                                    value = (tbValue[m].TotalLength * tuP[i].Item2).ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //UnitWeight
                                n++;
                                value = "";
                                if (tbValue[m].UnitWeight != 0)
                                    value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                }

                                //TotalWeight
                                n++;
                                value = "";
                                if (tbValue[m].TotalWeight != 0)
                                    value = (tbValue[m].TotalWeight * tuP[i].Item2).ToString("0.000").Trim();

                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    tb.Cells[i*3+m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextHeight = 2 * scale;
                                    tb.Cells[i*3+m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                    tb.Cells[i*3+m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                    tb.Cells[i*3+m + 2, n].Contents[0].TextStyleId = id;
                                    if(rowNum>14)
                                    {
                                        if ((i * 3 + m) % 3 == 0)
                                            tb.MergeCells(CellRange.Create(tb, i * 3 + m + 2, 2, i * 3 + m + 3, 2));
                                    }
                                }

                                if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                    _blcName = "MO";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                    _blcName = "MUC";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                    _blcName = "MUR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                    _blcName = "MU";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                    _blcName = "MSZR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                    _blcName = "MSZ";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                    _blcName = "MIXCR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                    _blcName = "MIXC0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                    _blcName = "MIXAR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                    _blcName = "MIXA0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                    _blcName = "MCR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                    _blcName = "MCL";
                                db.CopyBlockFromFile(_dwgPath, _blcName);
                                if (rowNum > 14)
                                {
                                    int co = 0;
                                    if ((i * 3 + m) / 3.0 > (int)(i * 3 + m) / 3)
                                        co = (int)(i * 3 + m) / 3 + 1;
                                    else
                                        co = (int)(i * 3 + m) / 3;
                                    if ((i * 3 + m) % 3 == 0)
                                    {
                                        if ((i * 3 + m) == 0)
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 7)), 0.8, _blcName, _dwgPath, 0);
                                        else
                                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 14 * (i * 3 + m - co * 2) + 18 * co + 11)), 0.8, _blcName, _dwgPath, 0);
                                    }
                                    else if (m % 3 == 2 )
                                        BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 14 * (i * 3 + m - co * 2) + 18 * co + 7)), 0.8, _blcName, _dwgPath, 0);
                                }
                                else
                                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 14 * (i*3+m) + 7)), 0.8, _blcName, _dwgPath, 0);

                            }
                            catch (Exception ex)
                            { }
                        }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    if (rowNum > 14)
                    {
                        if (i % 3 == 2 || i % 3 == 0)
                            tb.Rows[i].Height = 9 * scale;
                        else
                            tb.Rows[i].Height = 14 * scale;
                    }
                    else
                        tb.Rows[i].Height = 14 * scale;
                }

                #region 列单元格合并

              

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }


        public static Table DrawMergeColumnTable(Database db, Tuple<string, double, double, List<Tuple<Tuple<string, RebarCollection>, double>>> tuple, ref Extents2d ext,
 Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {
           
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (Tuple<Tuple<string, RebarCollection>, double> itemP in tuple.Item4)
                {
                    for(int i=0;i< itemP.Item2;i++)
                    {
                        RebarCollection tu = itemP.Item1.Item2;
                        foreach (RebarBase item in tu)
                        {
                            if (dic.Count == 0)
                            {
                                List<RebarBase> items = new List<RebarBase>();
                                items.Add(item);
                                dic[item.Diameter] = items;
                            }
                            else
                            {
                                List<RebarBase> items = new List<RebarBase>();
                                dic.TryGetValue(item.Diameter, out items);
                                if (items == null || items.Count == 0)
                                {
                                    items = new List<RebarBase>();
                                }
                                items.Add(item);
                                dic[item.Diameter] = items;
                            }
                        }
                    }
                   
                }
                #endregion

                #region 设置表格长宽

                int row = dic.Count + 2;
                int col = 5;
                row = dic.Count + 2;


                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", 45);
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = tuple.Item2.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion


                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 60 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);



                //CellRange range6 = CellRange.Create(tb, dic.Count + 2, 3, dic.Count + 2, 4);
                //cellList.Add(range6);


                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }
        #endregion


   

    }
}
